//package com.geely.pma.climate.api
package com.wanghaibo.vgashow.api;

import android.content.Context
import com.ecarx.xui.adaptapi.FunctionStatus
import com.ecarx.xui.adaptapi.car.base.ICarFunction.IFunctionValueWatcher
import io.reactivex.Single

interface ICarAdaptAPI {
    /**
     * must be called before using other methods
     *
     * @param context Context
     */
    fun init(context: Context)

    /**
     * reset instance of ICarAdaptAPI
     */
    fun destroy(clear: Boolean = true)

    /**
     * @param function function name
     * @return Single<List></List> < Integer> null if some error occurred
     */
    fun getSupportedFunctionValue(function: Int): Single<IntArray>

    /**
     * @param function function name
     * @return [&lt; FunctionStatus &gt;#error][Single] if some error occurred, such as initializing AdaptAPI failed
     */
    fun isFunctionSupported(function: Int): Single<FunctionStatus> =
        isFunctionSupported(function, null)

    fun isFunctionSupported(function: Int, zone: Int?): Single<FunctionStatus>

    fun setFunctionValue(function: Int, funcValue: Int): Single<Boolean> =
        setFunctionValue(function, null, funcValue)

    fun setFunctionValue(function: Int, zone: Int?, funcValue: Int): Single<Boolean>

    fun setCustomizeFunctionValue(function: Int, value: Float): Single<Boolean> =
        setCustomizeFunctionValue(function, null, value)

    fun setCustomizeFunctionValue(function: Int, zone: Int?, value: Float): Single<Boolean>

    /**
     * @param function function name
     * @return [&lt; ICarFunction &gt;#COMMON_VALUE_ERROR][Single] if some error occurred
     */
    fun getFunctionValue(function: Int): Single<Int> = getFunctionValue(function, null)

    fun getFunctionValue(function: Int, zone: Int?): Single<Int>

    /**
     * @param function function name
     * @return [&lt; Float &gt;#MIN_VALUE][Single] if some error occurred
     */
    fun getCustomizeFunctionValue(function: Int): Single<Float> =
        getCustomizeFunctionValue(function, null)

    fun getCustomizeFunctionValue(function: Int, zone: Int?): Single<Float>

    /**
     * get the value of `function` in `zones` when data is ready, and then value will be
     * returned if data is updated
     *
     * @param watcher  the watcher will be triggered if data is ready or updated
     * @param function car function name
     * @param zones     controlled zones
     *
     * @return true if observe successfully, otherwise false
     */
    fun observeCarFunctionValue(
        watcher: IFunctionValueWatcher, function: Int?, vararg zones: Int
    ): Boolean

    fun observeCarFunctionCustomize(
        watcher: IFunctionValueWatcher, function: Int?, vararg zones: Int
    ): Boolean

    fun observeSupportedFunctionStatus(
        watcher: IFunctionValueWatcher, function: Int?, vararg zones: Int
    ): Boolean

    fun stopObservation(watcher: IFunctionValueWatcher)
}